package servlet;

import dao.NoteDao;
import dao.UsersDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.sql.SQLException;

@WebServlet("/refresh.index")
public class ServletRefresh extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("进入刷新了");
        String username=ServletController.globaluser;
        UsersDao usersDao=new UsersDao();

        NoteDao noteDao = new NoteDao();
        //1、把指定表的所有数据查询到，然后绑定到session里面去
        try {
            req.getSession().setAttribute("users",usersDao.findUser(username));
            req.getSession().setAttribute("notes",noteDao.findAll());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        //5、登录成功，进入主页面，然后显示，欢迎您,xxx
        resp.sendRedirect("index.jsp");
    }
}
